@inject IJSRuntime JSRuntime
@inject IOptions<RuntimeOptions> RuntimeOptions
@inject NavigationManager NavigationManager

<CascadingAuthenticationState>
    <Router AppAssembly="@typeof(App).Assembly">
        <Found Context="routeData">
            <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
                <Authorizing>
                    <AcBlog.UI.Components.Loading.Loading />
                </Authorizing>
                <NotAuthorized>
                    @if (RuntimeOptions.Value.IsPrerender)
                    {
                        <AcBlog.UI.Components.Loading.Loading />
                    }
                    else
                    {
                        @if (!context.User.Identity.IsAuthenticated)
                        {
                            <RedirectTo Target="authentication/login" HasReturnUrl="true" />
                        }
                        else
                        {
                            <Result Status="403"
                                    Title=@("Forbidden")
                                    SubTitle=@("Sorry, you are not authorized to access this page.") />
                        }
                    }
                </NotAuthorized>
            </AuthorizeRouteView>
        </Found>
        <NotFound>
            <LayoutView Layout="@typeof(MainLayout)">
                <AcBlog.Client.UI.Pages.Pages.View Route="@NavigationManager.ToBaseRelativePath(NavigationManager.Uri)"/>
            </LayoutView>
        </NotFound>
    </Router>
</CascadingAuthenticationState>

<AntContainer />

@code{
    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        await LoadingInfoInterop.Hide(JSRuntime);
        await base.OnAfterRenderAsync(firstRender);
    }
}